package petAppium;

import java.io.IOException;
import java.net.MalformedURLException;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class Test1 extends BaseDriver {
	@DataProvider(name="excel")
	public  Object[][] getExcelDada() throws IOException{
		return new ExcelDataProvider().getTestDataByExcel("data/user.xlsx","Sheet1");
	}
//	// 手机号错误 因为此APP手机号出错时，图片一直在，无法定位
//	@Test(priority = 1)
//	public void login1() throws MalformedURLException, InterruptedException {
//		driver.findElementById("com.example.petwithlove:id/psw_login_tele").sendKeys("18311111");
//		Thread.sleep(1000);
//		driver.findElementById("com.example.petwithlove:id/login_password").sendKeys("123456");
//		Thread.sleep(1000);
//		driver.findElementById("com.example.petwithlove:id/btn_pswlogin").click();
//		driver.findElementByXPath(
//				"//android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ImageView")
//				.click();
//	}
	//注册新用户
	@Test(priority = 1)
	public void register() throws MalformedURLException, InterruptedException {
		driver.findElementById("com.example.petwithlove:id/tv_register").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/rb_love_people").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_regist_confirm").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/edt_username").sendKeys("周一");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/user_telephone").sendKeys("13191696232");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/first_psw").sendKeys("123456");
		driver.findElementById("com.example.petwithlove:id/second_psw").sendKeys("123456");
		driver.findElementById("com.example.petwithlove:id/btn_register_user").click();
		Thread.sleep(2000);
		driver.findElementById("com.example.petwithlove:id/btn_return").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_return").click();
	}
	//忘记密码
	@Test(priority = 2)
	public void rememberpwd() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/tv_forget").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/sms_login_tele").sendKeys("13191696232");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_smslogin").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_return").click();
	}
	//短信验证登录
	@Test(priority = 3)
	public void inf() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/tv_sms_verification").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/sms_login_tele").sendKeys("13191696232");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_smslogin").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_return").click();
	}
	
	// 密码错误	
	@Test(priority = 4)
	public void login2() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/psw_login_tele").sendKeys("18332299702");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/login_password").sendKeys("11");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_pswlogin").click();
	}

	// 验证登录是否成功
	@Test(priority = 5,dataProvider="excel")
	public void login3(String phone,String password) throws MalformedURLException, InterruptedException {
		driver.findElementById("com.example.petwithlove:id/psw_login_tele").sendKeys(phone);
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/login_password").sendKeys(password);
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_pswlogin").click();
	}

	// 底部+号功能
	@Test(priority = 6)
	public void add() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementByXPath(
				"//androidx.appcompat.app.ActionBar.Tab[3]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView")
				.click();
		Thread.sleep(3000);
		driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
		driver.findElementById("com.example.petwithlove:id/edt_textArea").sendKeys("撸猫去了");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_issuance").click();
	}

	// 底部+号功能中的上传照片
	@Test(priority = 7)
	public void addphoto() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementByXPath(
				"//androidx.appcompat.app.ActionBar.Tab[3]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView")
				.click();
		Thread.sleep(2000);
		if (driver.findElementByXPath("//android.widget.Button[@text='仅使用期间允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();

		}
		if (driver.findElementByXPath("//android.widget.Button[@text='允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
		}
//		driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
//		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/edt_textArea").sendKeys("第二次撸猫去了");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_select_photo").click();
		driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_select_photo").click();
		Thread.sleep(1000);
		driver.findElementByXPath("//android.widget.FrameLayout[6]/android.view.View").click();
		driver.findElementById("com.example.petwithlove:id/button_apply").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_issuance").click();
	}

	// 编辑资料进行保存
	@Test(priority = 8)
	public void edit() throws MalformedURLException, InterruptedException {
		driver.findElementByXPath(
				"//androidx.appcompat.app.ActionBar.Tab[5]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView")
				.click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_data").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/edt_location").sendKeys("66");
		driver.findElementById("com.example.petwithlove:id/btn_preservation").click();
	}

	// 编辑资料不进行保存
	@Test(priority = 9)
	public void notEdit() throws MalformedURLException, InterruptedException {
		driver.findElementByXPath(
				"//androidx.appcompat.app.ActionBar.Tab[5]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView")
				.click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_data").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/edt_location").sendKeys("777");
		driver.findElementById("com.example.petwithlove:id/btn_return").click();
	}

	// 社区信息进行点赞，收藏
	@Test(priority = 10)
	public void goods() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementByXPath(
				"//androidx.appcompat.app.ActionBar.Tab[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView")
				.click();
		Thread.sleep(1000);
		driver.findElementByXPath(
				"//android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.ImageButton[1]")
				.click();
		Thread.sleep(1000);
		driver.findElementByXPath(
				"//android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.ImageButton[3]")
				.click();
	}

	// 社区信息进行回复
	@Test(priority = 11)
	public void reply() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementByXPath(
				"//androidx.appcompat.app.ActionBar.Tab[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView")
				.click();
		Thread.sleep(1000);
		driver.findElementByXPath(
				"//android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.ImageButton[2]")
				.click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/tv_comment").sendKeys("猫咪很可爱");
		driver.findElementById("com.example.petwithlove:id/bt_commentUpload").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/bt_commentReturn").click();
	}

	// 我要救助功能
	@Test(priority = 12)
	public void rescue() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/ib_rescue").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/et_rescue_text").sendKeys("金毛脖子上戴着铃铛");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/et_rescue_name").sendKeys("金毛");
		driver.findElementById("com.example.petwithlove:id/et_rescue_phone").sendKeys("11111111111");
		driver.findElementById("com.example.petwithlove:id/et_rescue_address").sendKeys("河北省石家庄裕华区");
		driver.findElementById("com.example.petwithlove:id/rescue_radiobutton_lost").click();
		driver.findElementById("com.example.petwithlove:id/ib_rescue_choose_photo").click();
		Thread.sleep(2000);
		// 此处进行判断是否弹出开权限的页面，若弹出就点击开启，没有弹出就跳过
		if (driver.findElementByXPath("//android.widget.Button[@text='仅使用期间允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();

		}
		if (driver.findElementByXPath("//android.widget.Button[@text='允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
			Thread.sleep(2000);
			driver.findElementById("com.example.petwithlove:id/ib_rescue_choose_photo").click();
		}
		Thread.sleep(1000);
		driver.findElementByXPath("//android.widget.FrameLayout[6]/android.view.View").click();
		driver.findElementByXPath("//android.widget.FrameLayout[2]/android.widget.TextView[2]").click();
		Thread.sleep(2000);
		driver.findElementById("com.example.petwithlove:id/btn_rescue_submit").click();
	}

	// 我要寻找功能
	@Test(priority = 13)
	public void lost() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/ib_lost").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/et_rescue_text").sendKeys("哈士奇脖子上戴着铃铛");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/et_rescue_name").sendKeys("哈哈");
		driver.findElementById("com.example.petwithlove:id/et_rescue_phone").sendKeys("11111112222");
		driver.findElementById("com.example.petwithlove:id/et_rescue_address").sendKeys("河北省石家庄");
		driver.findElementById("com.example.petwithlove:id/ib_rescue_choose_photo").click();
		Thread.sleep(2000);
		if (driver.findElementByXPath("//android.widget.Button[@text='仅使用期间允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
		}
		if (driver.findElementByXPath("//android.widget.Button[@text='允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
			Thread.sleep(2000);
			driver.findElementById("com.example.petwithlove:id/ib_rescue_choose_photo").click();
		}
		Thread.sleep(1000);
		driver.findElementByXPath("//android.widget.FrameLayout[6]/android.view.View").click();
		driver.findElementByXPath("//android.widget.FrameLayout[2]/android.widget.TextView[2]").click();
		Thread.sleep(2000);
		driver.findElementById("com.example.petwithlove:id/btn_rescue_submit").click();
	}
	//更换头像
	@Test(priority = 14)
	public void update() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementByXPath("//androidx.appcompat.app.ActionBar.Tab[5]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_data").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_changeUserHead").click();
		Thread.sleep(1000);
		driver.findElementById("com.android.gallery3d:id/head_select_left").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_preservation").click();
	}

	// 救助页查询
	@Test(priority = 15)
	public void search() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/search_button").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/search_src_text").sendKeys("八哥鸟");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/search_close_btn").click();
	}

	// 点击轮播图
	@Test(priority = 16)
	public void clickImage() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementByXPath("//androidx.viewpager.widget.ViewPager/android.widget.ImageView").click();
	}
	//宠物对比
	@Test(priority = 17)
	public void contrast() throws MalformedURLException, InterruptedException {
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/ib_pet_contrast").click();
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_sure").click();
		Thread.sleep(1000);
		if(driver.findElementById("com.example.petwithlove:id/btn_pswlogin") == null) {
			return;
		}else {
			driver.findElementById("com.example.petwithlove:id/psw_login_tele").sendKeys("18332299702");
			Thread.sleep(1000);
			driver.findElementById("com.example.petwithlove:id/login_password").sendKeys("123456");
			Thread.sleep(1000);
			driver.findElementById("com.example.petwithlove:id/btn_pswlogin").click();
		}
	}

	// 发送信息
	@Test(priority = 18)
	public void addinfor() throws MalformedURLException, InterruptedException {
		Thread.sleep(2000);
		driver.findElementByXPath(
				"//androidx.appcompat.app.ActionBar.Tab[4]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView")
				.click();
		Thread.sleep(1000);
		if (driver.findElementByXPath("//android.widget.Button[@text='仅使用期间允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();

		}
		if (driver.findElementByXPath("//android.widget.Button[@text='允许']") == null) {
			return;
		} else {
			driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
		}

		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/edt_toChatUser").sendKeys("宠物救治所");
		Thread.sleep(1000);
		driver.findElementById("com.example.petwithlove:id/btn_chat").click();
		Thread.sleep(1000);
		driver.findElementById("com.android.permissioncontroller:id/permission_allow_button").click();
	}

	
}
